home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / BATTMEM.CMM < prev    next >
Text File  |  1994-03-04  |  6KB  |  179 lines

  1. /*********************************************************************************
  2.  *** Battmem.bat - Display status saved in battery-backed memory registers.    ***
  3.  *** ver.1         This examples programs displays how to use CEnvi to read    ***
  4.  ***               data from hardware ports, and how to manipulate bits within ***
  5.  ***               a byte.                                                     ***
  6.  *********************************************************************************/
  7.  
  8. printf("These are values read from battery-operated memory:\n");
  9.  
  10. #define  CLOCK_ADDRESS_REG    0x70  // put address to read here
  11. #define  CLOCK_READ_REG       0x71  // read value from address
  12. #define  BLANK_LINE           printf("\n")
  13.  
  14. BLANK_LINE
  15. /*****************************************************/
  16. /* SHOW ERRORS THAT MAY OCCUR IN THE DIAGNOSTIC BYTE */
  17. /*****************************************************/
  18. #define  DIAGNOSTIC_REG_ADDRESS  0x0E
  19. #define  DIAG_BYTES_UNUSED       0x03
  20. #define  DATETIME_ERROR          0x04
  21. #define  HARD_DRIVE_ERROR        0x08
  22. #define  MEMSIZE_ERROR           0x10
  23. #define  BAD_CONFIG_BYTE         0x20
  24. #define  CHECKSUM_ERROR          0x40
  25. #define  DEAD_CLOCK_BATTERY      0x80
  26.  
  27. diag = ReadByte(DIAGNOSTIC_REG_ADDRESS) & ~DIAG_BYTES_UNUSED
  28. if ( 0 == diag )
  29.    printf("No errors in the Diagnostic Byte Structure.\n")
  30. else {
  31.    if ( diag & DATETIME_ERROR )
  32.       printf("Date or time incorrect!\a\n")
  33.    if ( diag & HARD_DRIVE_ERROR )
  34.       printf("Hard drive or controler error!\a\n")
  35.    if ( diag & MEMSIZE_ERROR )
  36.       printf("Memory size incorrect!\a\n")
  37.    if ( diag & BAD_CONFIG_BYTE )
  38.       printf("Configuration byte is incorrect!\a\n")
  39.    if ( diag & CHECKSUM_ERROR )
  40.       printf("Checksum incorrect!\a\n")
  41.    if ( diag & DATETIME_ERROR )
  42.       printf("Realtime battery clock is dead!\a\n")
  43. }
  44.  
  45. BLANK_LINE
  46. /*******************************/
  47. /* STATUS AT SYSTEM POWER DOWN */
  48. /*******************************/
  49. #define  POWERDOWN_REG     0x0F
  50. printf("Status at system powerdown = %d\n",ReadByte(POWERDOWN_REG))
  51.  
  52.  
  53. BLANK_LINE
  54. /***********************************/
  55. /* STATUS OF FIRST TWO DISK DRIVES */
  56. /***********************************/
  57. #define  DRIVETYPE_REG     0x10
  58. DriveTypes = ReadByte(DRIVETYPE_REG)
  59. printf("The first floppy drive is type: %s\n", DriveDescription(Bits(DriveTypes,4,4)) )
  60. printf("The second floppy drive is type: %s\n", DriveDescription(Bits(DriveTypes,0,4)) )
  61.  
  62. DriveDescription(type)
  63. {
  64.    switch( type ) {
  65.       case 0
  66.          description = "Not Installed"
  67.          break
  68.       case 1
  69.          description = "5-1/4, 320/360K"
  70.          break
  71.       case 2
  72.          description = "5-1/4, 1.2 meg"
  73.          break
  74.       case 3
  75.          description = "3-1/2, 720K"
  76.          break
  77.       case 4
  78.          description = "3-1/2, 1.44 meg"
  79.          break
  80.       default
  81.          sprintf(description,"Unknown drive type %d",type)
  82.          break
  83.    }
  84.    return(description)
  85. }
  86.  
  87.  
  88. BLANK_LINE
  89. /***************************************/
  90. /* SHOW TYPES OF FIRST TWO HARD DRIVES */
  91. /***************************************/
  92. #define  HARD_DRIVE_1_REG     0x11
  93. #define  HARD_DRIVE_2_REG     0x12
  94. printf("Hard drive 1 is type %d\n",ReadByte(HARD_DRIVE_1_REG))
  95. printf("Hard drive 2 is type %d\n",ReadByte(HARD_DRIVE_2_REG))
  96.  
  97.  
  98. BLANK_LINE
  99. /**********************************/
  100. /* SHOW CONFIGURATION INFORMATION */
  101. /**********************************/
  102. #define  CONFIGURATION_REG    0x14
  103. #define  NO_DRIVE_OFFSET      0
  104. #define  COPROCESSOR_OFFSET   1
  105. #define  HARDDRIVE_ERROR_OFF  3
  106. #define  VIDEO_STARTUP_OFF    4
  107. #define  VIDEO_STARTUP_COUNT  2
  108. #define  DISK_DRIVE_COUNT_OFF 6
  109. #define  DISK_DRIVE_COUNT_NUM 2
  110. config = ReadByte(CONFIGURATION_REG)
  111. printf("At lease 1 disk drive is%s installed.\n",Bits(config,NO_DRIVE_OFFSET,1) ? "" : " NOT" )
  112. printf("Math coprocessor is%s installed.\n",Bits(config,COPROCESSOR_OFFSET,1) ? "" : " NOT" )
  113. if Bits(config,HARDDRIVE_ERROR_OFF,1)
  114.    printf("Hard drive or controller error.\n")
  115. printf("Video mode at startup is: ")
  116. switch( Bits(config,VIDEO_STARTUP_OFF,VIDEO_STARTUP_COUNT) ) {
  117.    case 0      printf("unknown.\n")                   break
  118.    case 1      printf("CGA/EGA/VGA, 40 columns.\n")   break
  119.    case 2      printf("CGA,EGA,CGA, 80 columns.\n")   break
  120.    case 3      printf("MDA/Hercules, 80 columns\n")   break
  121. }
  122. printf("Number of disk drives = %d.\n",Bits(config,DISK_DRIVE_COUNT_OFF,DISK_DRIVE_COUNT_NUM))
  123.  
  124.  
  125. BLANK_LINE
  126. /***********************************************/
  127. /* SHOW MAIN MEMORY AND EXPANSION MEMORY SIZES */
  128. /***********************************************/
  129. #define  MEM_SIZE_REG         0x15
  130. #define  EXPANSION_MEM_REG    0x17
  131. #define  EXPANSION2_REG       0x30
  132. printf("Main memory size = %d K-bytes\n",ReadWord(MEM_SIZE_REG))
  133. printf("Expansion board's main memory size = %d K-bytes\n",ReadWord(EXPANSION_MEM_REG))
  134. printf("Expansion memory size = %d K-bytes\n",ReadWord(EXPANSION2_REG))
  135.  
  136.  
  137. BLANK_LINE
  138. /***************************/
  139. /* TIME, DATE, AND CENTURY */
  140. /***************************/
  141. #define  CENTURY_REG       0x32
  142. #define  CLOCK_STATUS_REG  0x0B
  143. century = ReadByte(CENTURY_REG)
  144. printf("Century is: %d%d00\n",Bits(century,4,4),Bits(century,0,4))
  145. clock = ReadByte(CLOCK_STATUS_REG)
  146. printf("Daylight savings time is%s in effect.\n",Bits(clock,0,1) ? "" : " not" )
  147. printf("Time is kept in %d hour format.",Bits(clock,1,1) ? 24 : 12 )
  148.  
  149. /***************************************************************/
  150. /* All done; wait until a key is pressed or the program closed */
  151. /***************************************************************/
  152. if ( defined(_WINDOWS_) )
  153.    getch();
  154.  
  155. /******************************************/
  156. /* UTILITY FUNCTIONS USED IN THIS PROGRAM */
  157. /******************************************/
  158.  
  159. Bits(ByteValue,BitOffset,BitCount)
  160.    // return specific bits in a byte, and shift them to the right.
  161. {
  162.    // clear all bits above BitCount
  163.    for ( mask = 0, i = 0; i < BitCount; i++ )
  164.       mask |= 1 << i
  165.    return((ByteValue >> BitOffset) & mask)
  166. }
  167.  
  168. ReadByte(RegisterAddress)
  169. {
  170.    outport(CLOCK_ADDRESS_REG,RegisterAddress)
  171.    return(inport(CLOCK_READ_REG))
  172. }
  173.  
  174. ReadWord(RegisterAddress)
  175. {
  176.    return( ReadByte(RegisterAddress) | ( ReadByte(RegisterAddress+1) << 8 ) )
  177. }
  178.  
  179.